from django.shortcuts import render
from index.models import tieba
from django.http import JsonResponse
# Create your views here.
def index(request):
    print(request.GET)
    dirc=set()
    tmp=""
    for i in tieba.objects.all():
        if i.tieba_name not in dirc:
            dirc.add(i.tieba_name)
    return render(request,'index.html',{'dirc':dirc})

def ajax(request):
    baname=request.GET['tieba']
    img_count=tieba.objects.filter(tieba_name=baname).count()
    return JsonResponse(img_count,safe=False)

def ajax_img_url(request):
    baname=request.GET['tieba']
    index=request.GET['index']
    img_url=tieba.objects.filter(tieba_name=baname,img_count=index)[0].img_url
    return JsonResponse(img_url,safe=False)